﻿using ICSharpCode.TextEditor;
using ICSharpCode.TextEditor.Document;
using ICSharpCode.WinFormsUI.Docking;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DevelopAssistant.Core.DBMS
{
    public partial class CodeTextDocument : DockContent, IDocumentContent
    {
        int imageIndex = 0;

        private string _selectedDatabaseType;
        public string SelectedDatabaseType
        {
            get { return _selectedDatabaseType; }
            set { _selectedDatabaseType = value; }
        }

        public CodeTextDocument()
        {
            InitializeComponent();
        }

        public CodeTextDocument(MainForm owner)
            : this()
        {
            imageIndex = 0;
            tabControl1.Radius = 1;
            tabControl1.ShowClose = false;
            tabControl1.TabCaptionLm = -3;
            tabControl1.ItemSize = new System.Drawing.Size(94, 26);
            tabControl1.BorderColor = SystemColors.ControlDark;
            //tabControl1.ArrowColor = Color.White;
            tabControl1.BaseColor = SystemColors.Control;
            tabControl1.BackColor = SystemColors.Control;
            tabControl1.SizeMode = System.Windows.Forms.TabSizeMode.Fixed;
        }

        public void AddCodeTabPage(string codeText,string tabText)
        {
            TabPage newTabPage = new TabPage(tabText);
            newTabPage.ImageIndex = imageIndex;
            ICSharpCode.TextEditor.TextEditorControl textPad = new ICSharpCode.TextEditor.TextEditorControl();
            newTabPage.Controls.Add(textPad);
            textPad.SetHighlighting("C#");
            textPad.Text = codeText;
            textPad.Dock = DockStyle.Fill;
            this.tabControl1.TabPages.Add(newTabPage);
            textPad.Document.FormattingStrategy = new CSharpFormattingStrategy();
            textPad.Document.FoldingManager.FoldingStrategy = new IndentFoldingStrategy();
            textPad.Document.FoldingManager.UpdateFoldings();
            imageIndex++;
            textPad.TextChanged += new EventHandler(textPad_TextChanged);
        }

        private void textPad_TextChanged(object sender, EventArgs e)
        {
            ((TextEditorControl)(sender)).Document.FoldingManager.UpdateFoldings();
        }


        public void FindAndReplace(FindAndReplaceRequest request)
        {

        }

    }
}
